package com.ysd.lis.service.lab.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.lab.WlConfigPatsetting;
import com.ysd.lis.entity.lab.WlConfigResultssetting;
import com.ysd.lis.mapper.lab.WlConfigResultssettingMapper;
import com.ysd.lis.request.wl.WlConfigSettingParam;
import com.ysd.lis.service.lab.WlConfigResultssettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 结果列表配置 服务实现类
 * </p>
 *
 * @author WangHao
 * @since 2024-01-18
 */
@Service
public class WlConfigResultssettingServiceImpl extends ServiceImpl<WlConfigResultssettingMapper, WlConfigResultssetting> implements WlConfigResultssettingService {

    @Autowired
    private  WlConfigResultssettingMapper wlConfigResultssettingMapper;
    @Override
    public Result findResultstingByConfigId(WlConfigSettingParam wlConfigParam) {
        if (StringUtils.isBlank(wlConfigParam.getWLConfigId())) {
            return Result.fail("信息配置id不能为空");
        }
        LambdaQueryWrapper<WlConfigResultssetting> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WlConfigResultssetting::getDelFlag, 0);
        lambdaQueryWrapper.eq(WlConfigResultssetting::getWlConfigId, wlConfigParam.getWLConfigId());
        lambdaQueryWrapper.eq(Objects.nonNull(wlConfigParam.getIsVisiable()), WlConfigResultssetting::getIsVisiable, wlConfigParam.getIsVisiable());
        lambdaQueryWrapper.orderByAsc(WlConfigResultssetting::getDisplayOrder);
        List<WlConfigResultssetting> wlConfigResultssettings = wlConfigResultssettingMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功", wlConfigResultssettings);
    }

    @Override
    public Result insertOrUpdateResultsting(List<WlConfigResultssetting> wlConfigResultssetting) {
        boolean b = this.saveOrUpdateBatch(wlConfigResultssetting);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }
}
